package com.jhd.jiangxi.barcode;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.widget.Toast;


public class NLScan {
    private static BarcodeDataReceiver barcodeDataReceiver=null;

    static class BarcodeDataReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            final String scanResult_1 = intent.getStringExtra("SCAN_BARCODE1");
            final String scanResult_2 = intent.getStringExtra("SCAN_BARCODE2");
            final int barcodeType = intent.getIntExtra("SCAN_BARCODE_TYPE", -1); // -1:unknown
            final String scanStatus = intent.getStringExtra("SCAN_STATE");
            if ("ok".equals(scanStatus)) {
                //成功
                System.out.println("扫描结果1:" + scanResult_1 + "扫描结果2:" + scanResult_2 + "扫描结果3:" + barcodeType);
                Toast.makeText(context,"扫描结果1:" + scanResult_1 + "扫描结果2:" + scanResult_2 + "扫描结果3:" + barcodeType,Toast.LENGTH_SHORT).show();
                //tv_broadcast_result.setText(scanResult_1);
            } else {
                //失败如超时等
            }
        }
    }

    public static void openScan(Context context){
        barcodeDataReceiver = new BarcodeDataReceiver();
        IntentFilter mFilter = new IntentFilter("nlscan.action.SCANNER_RESULT");
        context.registerReceiver(barcodeDataReceiver, mFilter);
    }
}
